
** set path
// gl path ""

** open log
cap log close
log using "$path/table5.log", replace

***** Trump-specific effects, recent foreclosures

use "$path/foreclosures_analysis.dta", clear

gen trump = year == 2016
gen fore_trump = foreclosure_rate_six*trump

bootstrap _b, rep(1e3) seed(94305) cluster(fips) force: reghdfe pres_vs foreclosure_rate_six fore_trump trump [aw=pop_y], a(fips sy) cluster(fips)
local b1 = _b[foreclosure_rate_six]
local se1 = _se[foreclosure_rate_six]
local bint1 = _b[fore_trump]
local seint1 = _se[fore_trump]
local n1 = e(N)
local nclust1 = e(N_clust)

bootstrap _b, rep(1e3) seed(94305) cluster(fips) force: reghdfe pres_vs foreclosure_rate_six fore_trump trump [aw=pop_y], a(fips popyear) cluster(fips)
local b2 = _b[foreclosure_rate_six]
local se2 = _se[foreclosure_rate_six]
local bint2 = _b[fore_trump]
local seint2 = _se[fore_trump]
local n2 = e(N)
local nclust2 = e(N_clust)

bootstrap _b, rep(1e3) seed(94305) cluster(fips) force: reghdfe pres_vs foreclosure_rate_six fore_trump trump [aw=pop_y], a(i.fips##c.year sy) cluster(fips)
local b3 = _b[foreclosure_rate_six]
local se3 = _se[foreclosure_rate_six]
local bint3 = _b[fore_trump]
local seint3 = _se[fore_trump]
local n3 = e(N)
local nclust3 = e(N_clust)

bootstrap _b, rep(1e3) seed(94305) cluster(fips) force: reghdfe pres_vs foreclosure_rate_six fore_trump trump [aw=pop_y], a(i.fips##c.year popyear) cluster(fips)
local b4 = _b[foreclosure_rate_six]
local se4 = _se[foreclosure_rate_six]
local bint4 = _b[fore_trump]
local seint4 = _se[fore_trump]
local n4 = e(N)
local nclust4 = e(N_clust)

log close

quietly {
	cap log close
	set linesize 255
	log using "$path/foreclosure_trump_six.tex", text replace
	
	noisily dis "\begin{table}[t]"
	noisily dis "\centering"
	noisily dis "\caption{\textbf{Effects of Recent Housing Foreclosures on Presidential Elections, County Level, 2004--2016: Testing for Trump-Clinton Effects.}"
	noisily dis "\label{tab:trump_six}}"
	noisily dis "\begin{tabular}{lcccc}"
	noisily dis "\toprule \toprule"
	noisily dis " & \multicolumn{4}{c}{Dem Pres Vote Pct (0-100)}\\"
	noisily dis " & (1) & (2) & (3) & (4) \\"
	noisily dis "\midrule"
	noisily dis "Foreclosures Per 1,000 People & " %4.2f `b1' " & " %4.2f `b2' " & " %4.2f `b3' " & " %4.2f `b4'  "\\"
	noisily dis " & (" %4.2f `se1' ") & (" %4.2f `se2' ") & (" %4.2f `se3' ") & (" %4.2f `se4' ") \medskip \\"
	noisily dis "Foreclosures $ \times $ 2016 &  " %4.2f `bint1' " & " %4.2f `bint2' " & " %4.2f `bint3' " & " %4.2f `bint4'  "\\"
	noisily dis " & (" %4.2f `seint1' ") & (" %4.2f `seint2' ") & (" %4.2f `seint3' ") & (" %4.2f `seint4' ") \medskip \\"

	noisily dis " N & " %4.0f `n1' " & " %4.0f `n2' " & " %4.0f `n3' " & " %4.0f `n4' " \\ "
	noisily dis " \# Counties & "  %4.0f `nclust1' " & " %4.0f `nclust2' " & " %4.0f `nclust3' " & " %4.0f `nclust4' " \\ "
	noisily dis "County Fixed Effects & Y & Y & Y & Y  \\"
	noisily dis "State-Year Fixed Effects & Y & N & Y & N  \\"
	noisily dis "Pop Decile-Year Fixed Effects & N & Y & N & Y \\"
	noisily dis "County Linear Trends & N & N & Y & Y \\"
	noisily dis " Population Weights &  Y & Y & Y & Y \\"
	noisily dis "\bottomrule \bottomrule"
	noisily dis "\multicolumn{5}{p{.65\textwidth}}{\footnotesize Standard errors generated from 1,000 iterations of a county-level block bootstrap procedure.  "
	noisily dis "Main effect for 2016 is absorbed by fixed effects.}"
	noisily dis "\end{tabular}"
	noisily dis "\end{table}"
	
	log off
	
}
